package com.shanghaiyimu.yimiyangche.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.shanghaiyimu.yimiyangche.R;
import com.shanghaiyimu.yimiyangche.bean.SelectShopBean;

import java.util.List;

/**
 * Author:ShangHaiYiMu
 * Time:2017/7/18   14:20
 * Description:ShopSelectAnZhuangLvAdapter
 */

public class ShopSelectAnZhuangLvAdapter extends BaseAdapter {

    private Context context;
    private List<SelectShopBean> datas;

    public ShopSelectAnZhuangLvAdapter(Context context, List<SelectShopBean> datas) {
        this.context = context;
        this.datas = datas;
    }
    @Override
    public int getCount() {
        return datas!=null?datas.size():0;
    }

    @Override
    public SelectShopBean getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.select_shop_listview_item,parent,false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }

        SelectShopBean selectShopBean =datas.get(position);
        holder.name.setText(selectShopBean.getName());
        // 0 : 工厂店 1 ：4S店  2：快修店  3：维修店  4：星级保养店
        switch (selectShopBean.getShopType()){
            case 0:
                holder.shopType.setText("工厂店");
                break;
            case 1:
                holder.shopType.setText("4S店");
                break;
            case 2:
                holder.shopType.setText("快修店");
                break;
            case 3:
                holder.shopType.setText("维修店");
                break;
            case 4:
                holder.shopType.setText("星级保养店");
                break;
            default:
                break;
        }
        holder.quantity.setText(selectShopBean.getQuantity()+"单");
        holder.distance.setText(selectShopBean.getDistance()+"km");
        return convertView;
    }
    static class  ViewHolder{
        private TextView name,shopType,quantity,distance;
//        private String name;
//        // 评价
//        private int assess;
//        // 安装数量
//        private int quantity;
//        private String shopType;

        public ViewHolder(View view) {
            name = (TextView) view.findViewById(R.id.name_select_shop_lv_item);
            shopType = (TextView) view.findViewById(R.id.type_select_shop_item);
            quantity = (TextView) view.findViewById(R.id.anzhuangshuliang_select_shop_item);
            distance = (TextView) view.findViewById(R.id.juli_select_shop_item);

        }
    }
}
